<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>项目列表</title>
		<link rel="stylesheet" href="/dvmini/res/plugins/layui/css/layui.css">
		<link rel="stylesheet" href="/dvmini/res/css/basic.css">
	</head>
	<style>
		 .layui-form-label{
			width:90px;	
		}
		.Detailbtn .layui-input-inline{
			width:380px !important;
		} 
	</style>
	<body class="wrap">
		<form class="layui-form">
			<div class="layui-form-item searchbox" style="margin-bottom: 0px;">
				
				<!-- <div class="layui-input-inline producttype" style="width: 140px;">
					<select name="producttype" >
						<option value="">姓名</option>
					</select>
				</div>
				<div class="layui-input-inline productid" style="width: 140px;">
					<select name="productid">
						<option value="">项目id</option>
					</select>
				</div>
				<div class="layui-input-inline" style="width: 140px;">
					<input type="text" class="layui-input" name="keyword" placeholder="关键字" />
				</div>
				<button class="layui-btn" lay-submit lay-filter="querybtn">查询</button>
				<button class="layui-btn layui-btn-primary resetBtn">重置</button> -->
				<a class="layui-btn layui-btn-warm createBtn" href="#"><i class="layui-icon">&#xe61f;</i> 添加万小二</a>
			</div>
		</form>
		<table class="layui-table">
			<thead>
				<tr>
					<th style="width:30px;">No</th>
					<th style="min-width: 60px;">姓名</th>
					<th style="min-width: 100px;">手机</th>
					<th style="min-width: 80px;">修改时间 </th>
					<th style="min-width: 80px;">上次登录时间</th>
					<th style="min-width: 80px;">操作</th>
				</tr>
			</thead>
				
			<tbody id="tablelist">
				<!-- <tr>
					<td>No</td>
					<td style="min-widtd: 56px;">姓名</td>
					<td style="min-widtd: 56px;">手机</td>
					<td style="min-widtd: 56px;">小程序openid </td>
					<td style="min-widtd: 160px;">公众号openid</td>
					<td style="min-widtd: 56px;">修改时间 </td>
					<td style="min-widtd: 160px;">上次登录时间</td>
					<td>
						<a href="#" class="layui-btn layui-btn-mini updataBtn">修改</a>
						<a href="#" class="layui-btn layui-btn-mini deleteBtn">删除</a>
					</td>
				</tr> -->
			</tbody>
			</tbody>
		</table>
		<div class="nulldata">暂无数据</div>
		<div id="page"></div>
		
	</body>
	
	<form class="layui-form Detailbtn" >
		  <div class="layui-form-item">
		    <label class="layui-form-label">姓名</label>
		    <div class="layui-input-inline">
		      <input type="text" name="name" required  lay-verify="required" placeholder="姓名" autocomplete="off" class="layui-input">
		    </div>
		</div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">手机</label>
		    <div class="layui-input-inline">
		      <input type="text" name="phone" required  lay-verify="required" placeholder="手机" autocomplete="off" class="layui-input">
		    </div>
		</div>
		<!--   <div class="layui-form-item">
		    <label class="layui-form-label">小程序openid</label>
		    <div class="layui-input-inline">
		      <input type="text" name="title" required  lay-verify="required" placeholder="项目名称" autocomplete="off" class="layui-input">
		    </div>
		</div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">公众号openid</label>
		    <div class="layui-input-inline">
		      <input type="text" name="title" required  lay-verify="required" placeholder="项目名称" autocomplete="off" class="layui-input">
		    </div>
		</div> -->
	  
	  </form>
	<script src='/dvmini/res/js/jquery.min.js'></script>
	<script src="/dvmini/res/plugins/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="/dvmini/res/js/me.js"></script>
	<script>
		layui.use(['form', 'element', 'laydate', 'layer', 'laypage'], function() {
			var form = layui.form(),
				element = layui.element(),
				laydate = layui.laydate,
				layer = layui.layer,
				laypage = layui.laypage;
				var page=1;
				
				//初始化数据
				initdata(page);
				function initdata(page){
					
					$.post("/dvmini/vanker/getList",{page:page},function(data){
						data=data.data;
						console.log(data)
						 laypage({
							cont: 'page',
							pages: data.totalPages, //总页数
							curr: page,
							skip: true,
							jump: function(obj, first) {
								if(!first) {
									page = obj.curr
									initdata(page);
								}
	
							}
						}); 
						var str="";
						if(data.rows.length<1){
							$(".nulldata").show();
						}else{
							$(".nulldata").hide();
							for(var i=0;i<data.rows.length;i++){
								str+='<tr data-id='+ data.rows[i].id +'>'
									+'<td>'+ ((data.page - 1) * 5 + i + 1) +'</td>'
									+'<td>'+ data.rows[i].name+'</td>'
									+'<td>'+ data.rows[i].phone+'</td>'
									+'<td>'+ toTime_G(data.rows[i].createdtime) +'</td>'
									+'<td>'+ toTime_G(data.rows[i].lastlogintime) +'</td>'
									+'<td>'
									+'<a href="#" class="layui-btn layui-btn-mini updataBtn">修改</a>'
									+'<a href="#" class="layui-btn layui-btn-mini deleteBtn">删除</a>'
									+'</td>'
									+'</tr>';
							}
						}
						
						$("#tablelist").html(str);
					})
				}
				//添加万小二
			$(document).on("click",".createBtn",function(){
				layer.open({
					type:1,
					title:'添加万小二',
					area:["600px","380px"],
					content:$(".Detailbtn"),
					btnAlign:'c',
					btn:["确定","取消"],
					yes:function(index,layero){
						var name=$("input[name=name]").val();
						var phone=$("input[name=phone]").val();
						if(name==""){
							top.layer.msg("请填写名称");
							return false;
						}
						if(phone==""){
							top.layer.msg("请填写手机号");
							return false;
						}else{
							if(!(/^1[34578]\d{9}$/.test(phone))) {
								top.layer.msg("手机号码有误，请重填");
								return false;
							}
						}
						$.post("/dvmini/vanker/addvanker",{
							name:name,
							phone:phone
						},function(data){
							console.log(data);
							if(data.code==0){
								top.layer.msg("添加成功");
								layer.close(index);
								initdata(page);
							}else{
								top.layer.msg(data.msg);
							}
						}) 
					},
					btn2:function(index,layero){
						layer.close(index);
					},
					success:function(){
						$("input[name=name]").val("");
						$("input[name=phone]").val("");
					}
						
				})
			})
			//修改万小二
			$(document).on("click",".updataBtn",function(){
				var id=$(this).parents("tr").attr("data-id");
				layer.open({
					type:1,
					title:'修改万小二',
					area:["600px","380px"],
					content:$(".Detailbtn"),
					btnAlign:'c',
					btn:["确定","取消"],
					yes:function(index,layero){
						var name=$("input[name=name]").val();
						var phone=$("input[name=phone]").val();
						if(name==""){
							top.layer.msg("请填写名称");
							return false;
						}
						if(phone==""){
							top.layer.msg("请填写手机号");
							return false;
						}else{
							if(!(/^1[34578]\d{9}$/.test(phone))) {
								top.layer.msg("手机号码有误，请重填");
								return false;
							}
						}
						$.post("/dvmini/vanker/updatevanker",{
							id:id,
							name:name,
							phone:phone
						},function(data){
							console.log(data);
							 if(data.code==0){
								top.layer.msg("修改成功");
								layer.close(index);
								initdata(page);
							}else{
								top.layer.msg(data.msg);
							}
						})
					},
					btn2:function(index,layero){
						layer.close(index);
					},
					success:function(){
						
						$.post("/dvmini/vanker/getVanker",{
							id:id
						},function(data){
							console.log(data);
							  if(data.code==0){
								$("input[name=name]").val(data.data.name);
								$("input[name=phone]").val(data.data.phone);
							}  
						}) 
					}
				})
			})
			
			//删除项目
			$(document).on("click", ".deleteBtn", function() {
				var id=$(this).parents("tr").attr("data-id");
				layer.confirm('您确定要删除该万小二吗？', {
					btn: ['确定', '取消'] //按钮
				}, function(index, layero) {
					$.post( "/dvmini/vanker/deletevanker",{id:id}, function(data) {
						console.log(data)
						if(data.code == 0) {
							top.layer.msg("删除成功");
							initdata(page);
							layer.close(index);
						}else{
							top.layer.msg(data.msg);
						}
					})
				}, function(index, layero) {
					layer.close(index);
				});
			});

		})
	//验证变量是否为null
	function nullToSpace (v) {
	　　 return  !v && v != '0' ? '' : v;
	}
		
	</script>

</html>